import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import store from '../store/index'
import { Toast } from 'vant';

Vue.use(Toast);

Vue.use(VueRouter)

const routes = [
  {
    path: '/one',
    name: 'one',
    component: () => import('../views/one.vue'),
  },
  {
    path: '/fen',
    name: 'fen',
    component: () => import('../views/fen.vue')
  },
  {
    path: '/cart',
    name: 'cart',
    component: () => import('../views/cart.vue')
  },
  {
    path: '/my',
    name: 'my',
    component: () => import('../views/my.vue'),
    beforeEnter: (to, from, next) => {
      if(store.state.token==''){
        Toast.success('请先登录')
        next('/login')
      }else{
        next()
      }

    }
  },
  {
    path: '/kjxq',
    name: 'kjxq',
    component: () => import('@/components/kan/kjxq')
  },
  {
    path: '/jxxq',
    name: 'jxxq',
    component: () => import('@/components/jingxuan/jxxq')
  },
  {
    path: '/tjxq',
    name: 'tjxq',
    component: () => import('@/components/renqi/tjxq')
  },
  {
    path: '/sou',
    name: 'sou',
    component: () => import('@/components/search/sou')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login.vue')
  },
  {
    path: '/detail',
    name: 'detail',
    component: () => import('../views/detail.vue')
  },
  {
    path:'/',
    redirect:'/one'
  }
]

const router = new VueRouter({
  routes
})

export default router
